package com.paic.mhis.mis;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.paic.mhis.mis.data.City;
import com.paic.mhis.mis.data.Menu;
import com.paic.mhis.mis.service.CityService;
import com.paic.mhis.mis.service.MenuService;

@RequestMapping("/menus")
@RestController
public class MenuController {

	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	private CityService cityService;
	
	@Autowired
	private MenuService menuService;
	
	@RequestMapping(value="/getCities/{cityName}")
	public City getCities(@PathVariable("cityName") String cityName) {
		City c = cityService.findCityByName(cityName);
		
		return c;
	}
	@RequestMapping(value = "/{roles}", method = RequestMethod.GET)
    public List<Menu> getMenus(@PathVariable("roles") String roles) {
		if (StringUtils.isBlank(roles))
			return new ArrayList<Menu>();
		logger.info("abctest");
		String[] roleArray = roles.split(",");
		List<Menu> m = menuService.getMenus(roleArray);
		return m;
//        return "Hello2 " + name;
//		return "service 2, menus for role: " + roles;
//		Menu m1 = new Menu();
//		m1.setId("1");
//		m1.setPath("www.baidu.com");
//		m1.setName("first menu");
//		m1.setComponent("first menu");
//		m1.setOrder(10000);
//		
//		Menu m1sub = new Menu();
//		m1sub.setId("1.1");
//		m1sub.setPath("www.sina.com.cn");
//		m1sub.setName("first sub-menu");
//		m1sub.setComponent("first sub-menu");
//		m1sub.setOrder(11000);
//		
//		m1.getChildren().add(m1sub);
//		
//		return m1;
    }
}